<?php
session_start();
include("../includes/conn.php");
$dbconn->admin_logincheck();
$adminid=$_SESSION['adminid'];
$id = isset($_GET['id'])?$_GET['id']:'';
$act = isset($_GET['act'])?$_GET['act']:'';
if($_GET['act']=='edit')
{
	$selrow=$dbconn->fetch($dbconn->query("select b.*,p.img from ".DBQIAN."buylog b join ".DBQIAN."product p on b.product_id=p.id where b.id=$id"));
	switch ($selrow['status'])
	{
		case 1: $selrow['status']="等待买家付款";break;
		case 2: $selrow['status']="等待店铺发货";break;
		case 3: $selrow['status']="等待买家付款";break;
		case 4: $selrow['status']="等待买家收货";break;
		case 5: $selrow['status']="等待店铺发货";break;
		case 6: $selrow['status']="交易完成";break;
		case 7: $selrow['status']="订单已关闭";break;
		case 8: $selrow['status']="订单被卖家关闭";break;
	}
}
//添加
if($_GET['act']=='add'){
	//print_r($_FILES['img']);exit;
	if ($_FILES&&!empty($_FILES['img']['name']))
	{
		$result = upload($_FILES['img']);
		//print_r($result);exit;
		if ($result&&$result['result'] == 1)
		{
			$img = $result['path'];
			unlink($selrow['img']);
		}
		else 
		{
			$dbconn->showalert("图片上传失败","product.php",1);	exit;
		}
	}
	else 
	{
		$img = $_POST['img1'];
	}
	//echo $img;exit;
	$name = $_POST['name'];
	$price = $_POST['price'];
	$color = $_POST['color'];
	$size = $_POST['size'];
	$desc = htmlspecialchars($_POST['content1']);//exit;
	$time = date('Y-m-d H:i:s',time());
//	echo 'insert into '.DBQIAN.'product(title,desc,time,content,url) values(\''.$title.'\',\''.$desc.'\',\''.$time.'\',\''.$content.'\',\''.$url.'\')';exit;
	$dbconn->noretquery("update ".DBQIAN."product set `name`='$name',`desc`='$desc',`img`='$img',`time`='$time',`color`='$color',`size`='$size',`price`='$price' where id=".$id);
	$dbconn->showalert("保存成功","product.php",1);
}

function upload($file)
{
	$picname = $file['name'];
	$picsize = $file['size'];
	if ($picname != "") 
	{
		if ($picsize > 1024000) 
		{
			echo '图片大小不能超过1M';
			exit;
		}
		$type = strstr($picname, '.');
		if ($type != ".gif" && $type != ".jpg" && $type != ".png") 
		{
			echo '图片格式不对！';
			exit;
		}
		$rand = rand(100, 999);
		$pics = date("YmdHis") . $rand . $type;
		//上传路径
		$pic_path = "../user/images/product/". $pics;
		$result = move_uploaded_file($file['tmp_name'], $pic_path);
	}
	$arr = array(
		'name'=>$picname,
		'path'=>$pic_path,
		'pic'=>$pics,
		'size'=>$size,
		'result'=>$result
	);
	return $arr;
}

?><!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>欢迎登录后台管理系统</title>
<link href="css/base.css" rel="stylesheet" type="text/css" />
<link href="css/right.css" rel="stylesheet" type="text/css">
<!--<link href="css/select.css" rel="stylesheet" type="text/css">-->
<link rel="stylesheet" href="k/themes/default/default.css" />
<link rel="stylesheet" href="k/plugins/code/prettify.css" />
<script charset="utf-8" src="k/kindeditor.js"></script>
<script charset="utf-8" src="k/lang/zh_CN.js"></script>
<script charset="utf-8" src="k/plugins/code/prettify.js"></script>
<script src="js/jquery.js"></script>
<script src="js/select-ui.min.js"></script>
<script type="text/javascript" src="js/uploadPreview.js"></script>
<style>
textarea{border-top: solid 1px #a7b5bc;border-left: solid 1px #a7b5bc;border-right: solid 1px #ced9df;border-bottom: solid 1px #ced9df;padding:5px;line-height:20px}
p{line-height:32px}
tr td{border-right: 1px solid #dddddd;}
hr{background: #dddddd;height: 1px;}
.hengfu{margin:10px auto;}
.orderdetail{}
.orderdetail tr{height:25px}
.orderdetail tr td{width:33.3%}
input{border:1px solid #dddddd;width: 200px;height: 28px;}
</style>
<script>
$(document).ready(function(){
   $(function(){
   		$("#submit").click(function(){
   	   	  id=$("#id").val();
   		  shippingnumber=$("#shippingnumber").val();
   		  note=$("#note").val();
   		  should_pay=$("#should_pay").val();
   		  act="editsave";
   		  $.post("ajax.orderedit.php",{id:id,act:act,shippingnumber:shippingnumber,note:note,should_pay:should_pay},function(result){
       		if (result=="success")
   		    {
//      			$("#result").toggle();
				$("#shippingnumber").attr("disabled",false);
				$("#status").val("已发货");
				alert("保存成功");
   		    }
   		    else
   		    {
				alert("修改失败");
   		    }
   		  });
   		});
   });
   
});

function getObjectURL(file) {
	var url = null ; 
	if (window.createObjectURL!=undefined) { // basic
		url = window.createObjectURL(file) ;
	} else if (window.URL!=undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file) ;
	} else if (window.webkitURL!=undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file) ;
	}
	return url ;
}


</script>
</head>
<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li><a href="index.php">首页</a></li>
    <li><a href="orderlist.php">订单管理</a></li>
    <li>编辑</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>订单编辑</span></div>
  <form name="radd" method="post" action="" enctype="multipart/form-data">
  <ul class="forminfo">
  	<li>
  		<label>订单编号</label>
  		<p><?=$selrow['ordernumber']?></p>
  	</li>
  	<li>
  		<label>创建时间</label>
  		<p><?=$selrow['create_time']?></p>
  	</li>
  	<li>
  		<label>订单状态</label>
  		<p><?=$selrow['status']?></p>
  	</li>
  	<li>
  		<label>支付状态</label>
  		<p><?=$selrow['paystatus']?"<font color='green'>已支付</font>":"<font color='red'>未支付</font>"?></p>
  	</li>
  	<li>
  		<label>发货状态</label>
  		<p><input type="button" id="status" value="<?=(!empty($selrow['shippingnumber'])?"已发货":"未发货")?>" style="color:<?=(!empty($selrow['shippingnumber'])?'green':'red')?>;background:none;border:none;text-align:left"/></p>
  	</li>
  	<li>
  		<label>物流单号</label>
  		<p><input type="text" name="shippingnumber" id="shippingnumber" placeholder="请正确填写单号" value="<?=$selrow['shippingnumber']?$selrow['shippingnumber']:'-'?>" disabled="disabled"/></p>
  	</li>
  	<li>
  		<label>收货地址</label>
  		<p><?=$selrow['name'].', '.$selrow['tel'].', '.$selrow['province'].' '.$selrow['city'].' '.$selrow['address']?></p>
  	</li>
  	<li>
       <label>图片</label>
	   <img style="width:100px" src="<?=$selrow['img']?>" id="img" >
	</li>
    <li>
      <label>购买产品</label>
      <p><?=$selrow['product_name']?></p>
      <i></i>
    </li>
    <li>
      <label>产品尺寸</label>
      <p><?=$selrow['size']?></p>
      <i></i>
    </li>
	<li>
      <label>颜色类别</label>
      <p><?=$selrow['color']?></p>
      <i></i>
    </li>
    <li>
      <label>单价</label>
      <p><?=$selrow['price']?></p>
    </li>
    <li>
      <label>购买数量</label>
      <p><?=$selrow['quantity']?></p>
    </li>
    <li>
      <label>总价</label>
      <p><?=$selrow['amount']?></p>
    </li>
    <li>
      <label>优惠金额</label>
      <p><?=$selrow['yh_price']?></p>
    </li>
    <li>
      <label>应支付</label>
      <p>
	      <input type="text" name="should_pay" id="should_pay" placeholder="请正确填写金额，例如：10.00" <?if ($selrow['paystatus']):?>disabled="disabled"<?endif;?> value="<?=$selrow['should_pay']?>"/>
	      <?if ($selrow['paystatus']):?><span style="color: gray">*买家已付款无法修改支付金额</span><?endif;?>
      </p>
    </li>
    <li>
      <label>备注</label>
      <p><textarea rows="4" cols="70" name="note" id="note"><?=$selrow['note']?></textarea></p>
    </li>
    <li>
      <label>&nbsp;</label>
      <input type="hidden" value="editsave"  name="act"  />
      <input type="hidden" value="<?=$selrow['id']?>"  name="id" id="id" />
      <input name="button" type="button" class="btn" id="submit"value="确认保存"/>
      <span id="result" style="display: none;background: gray">保存成功</span>
    </li>
  </ul>

  </form>
</div>
<script>
	KindEditor.ready(function(K) {
		var editor1 = K.create(\'textarea[name="content1"]\', {
			cssPath : 'k/plugins/code/prettify.css',
			uploadJson : 'k/php/upload_json.php',
			fileManagerJson : 'k/php/file_manager_json.php',
			allowFileManager : true,
			afterCreate : function() {
				var self = this;
				K.ctrl(document, 13, function() {
					self.sync();
					K('form[name=radd]')[0].submit();
				});
				K.ctrl(self.edit.doc, 13, function() {
					self.sync();
					K('form[name=radd]')[0].submit();
				});
			}
		});
		prettyPrint();
	});
</script>
</body>
</html>